import {Component} from '@angular/core';
import {NavController} from 'ionic-angular';
import {Helper} from "../../common/Helper";
import {UserProvider} from "../../providers/user/user";

@Component({
  selector: 'page-bill-history',
  templateUrl: 'bill-history.html',
})
export class BillHistoryPage {

  list: object[] = []
  nowPage: number = -1
  last: boolean = false

  constructor(public navCtrl: NavController,
              public user: UserProvider) {

  }

  ionViewWillEnter() {
    Helper.setStatusBarDefault()
  }

  getDetail(page = 0, success = () => {
  }) {
    this.user.getAccountDetail({
      data: {
        page: page
      },
      success: (data) => {
        this.list = this.list.concat(data.content)
        this.nowPage += 1
        this.last = data.lastPage
        success()
      }
    })
  }

  getMore(infiniteScroll) {
    setTimeout(() => {
      this.getDetail(this.nowPage + 1, () => {
        infiniteScroll.complete();
      })
    }, 500);
  }

  doRefresh(refresher){
    setTimeout(() => {
      // console.log('Async operation has ended');
      refresher.complete();
    }, 2000);
  }

  ionViewWillLoad() {
    this.getDetail()
  }

}
